package com.hongxinguoji.manager.admin.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hongxinguoji.manager.admin.mapper.HxAuthFunctionMapper;
import com.hongxinguoji.manager.admin.mapper.HxRoleFunctionMapper;
import com.hongxinguoji.manager.admin.pojo.HxAuthFunction;
import com.hongxinguoji.manager.admin.pojo.HxAuthFunctionExample;
import com.hongxinguoji.manager.admin.pojo.HxRoleFunctionKey;
import com.hongxinguoji.manager.admin.service.IFunctionService;

@Service
public class FunctionServiceImpl implements IFunctionService {

	@Autowired
	private HxAuthFunctionMapper functionMapper;

	@Override
	public List<HxAuthFunction> getFunctionList() {

		// 查询所有数据
		HxAuthFunctionExample example = new HxAuthFunctionExample();
		List<HxAuthFunction> list = functionMapper.selectByExample(example);

		return list;

	}

	@Override
	public List<HxAuthFunction> functionListajax() {
		HxAuthFunctionExample example = new HxAuthFunctionExample();
		List<HxAuthFunction> list = functionMapper.selectByExample(example);
		return list;
	}

	@Override
	public void functionAdd(HxAuthFunction function) {
		functionMapper.insert(function);

	}

	@Override
	public void functionUpdate(HxAuthFunction function) {
		String id = function.getId();

		HxAuthFunction authFunction = functionMapper.selectByPrimaryKey(id);
		// code chakanwenzhang
		// description generatemenu
		// id 145637858221560
		// name 查看文章
		// pId 145637842250652
		// page article/articleList
		// zindex 1
		// 更新数据
		authFunction.setGeneratemenu(function.getGeneratemenu());
		authFunction.setPage(function.getPage());
		authFunction.setZindex(function.getZindex());
		authFunction.setName(function.getName());
		authFunction.setDescription(function.getDescription());
		authFunction.setCode(function.getCode());

		// 提交数据
		functionMapper.updateByPrimaryKey(authFunction);
	}

	@Autowired
	private HxRoleFunctionMapper roleFunctionMapper;

	@Override
	public void deleteUserById(String id) {

		HxRoleFunctionKey key = new HxRoleFunctionKey();
		key.setFunctionId(id);
		// 删除对应的外键
		roleFunctionMapper.deleteByPrimaryKey(key);

		// 删除权限表数据
		functionMapper.deleteByPrimaryKey(id);

	}

}
